package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqStepAndBatteryMessage;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import org.springframework.beans.factory.annotation.Autowired;

public class UploadStepReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // 解析到指令：*WT,800115470000876,STEP,120057,0,82,160621,FDFFFFFF
        //分割字符串获取指令信息
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String commandNumber = split[3];
        String stepNum = split[4];//步数
        String battery = split[5];  // 电量
        String date = split[6];//日月年
        String deviceStatus = split[7];
        MqStepAndBatteryMessage mqStepAndBatteryMessage = new MqStepAndBatteryMessage();
        mqStepAndBatteryMessage.setBattery(Integer.parseInt(battery));
        mqStepAndBatteryMessage.setCommandNumber(commandNumber);
        mqStepAndBatteryMessage.setImei(imei);
        mqStepAndBatteryMessage.setDeviceDate(date);
        mqStepAndBatteryMessage.setStepNum(Integer.parseInt(stepNum));
        mqStepAndBatteryMessage.setDeviceTime(commandNumber);
        mqStepAndBatteryMessage.setDeviceStatus(deviceStatus);
        InjectFeignService.getIrmFeignClientService().upStepMessage(mqStepAndBatteryMessage);
        return imei;
    }
}
